<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Item_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
        $this->record_table = $this->db->dbprefix("item_copy_record");

    }

    /**
     * @param array $data
     * @return bool
     */
    public function copy_log_add(array $data)
    {
         if($this->db->insert($this->record_table, $data))
         {
            return $this->db->insert_id();
         }

        return FALSE;
    }



    /**
     *
     * 获取记录总数量
     * @param array $where 查询条件
     */
    public function get_record_count($where='')
    {
        $this->db->select('id');
        if(!empty($where)) $this->db->where($where);
        $this->db->from($this->record_table);
        return $this->db->count_all_results() ;
    }

    /**
     * 获取所有复制记录
     * @param array $where 选择条件
     */

    public function get_record_list($where='',$page_size=20,$now_page=1)
    {
        $this->db->order_by('crts','desc');
        if(!empty($where)) $this->db->where($where);
        $query = $this->db->get($this->record_table,$page_size,($now_page-1)*$page_size);
        return $query->result_array();
    }

    /**
     * 获取所有复制过的原商品ids
     * @param array $where 选择条件
     */

    public function get_record_oids()
    {
        $this->db->select('onum_iid');
        $query = $this->db->get($this->record_table);
        return $query->result_array();
    }
}